package com.zhouyu.fileSync.FScommon.commonUtils;

import org.apache.commons.codec.digest.DigestUtils;

import java.io.File;
import java.io.FileInputStream;
import java.util.Date;

public class FileUtils {

    public static String getMd5(File file) throws Exception {
        isFile(file);
        return DigestUtils.md5Hex(new FileInputStream(file));
    }

    public static Long getFileSize(File file) throws Exception {
        isFile(file);
        return file.lastModified();

    }

    public static Long getFileLastModified(File file) throws Exception {
        isFile(file);
        return file.lastModified();

    }

    private static void isFile(File file) throws Exception {
        if (file==null||file.isDirectory()){
            throw new Exception("文件不存在或不是一个文件");
        }
    }

}
